<?php
/**
 * @Notes:【】
 * @Date: 2022-06-05 15:23
 */

namespace Form;

use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\PostApi;
use Yj\ColumnBuilder\Column;
use Yj\Form\Elm;

/**
 * @ApiController(prefix="form/order_refund")
 */
class OrderRefund extends BaseForm
{
    protected $yjCode = 'orderRefund';

    protected $routes = [
        'lists' => '/admin/order/order_refund/lists',
        'add' => '/admin/order/order_refund/add',
        'form' => '/form/order_refund/update',
    ];

    public function getColumn()
    {
        $colum = Column::create();
        $colum->setRules([
            Column::txt()->setLabel('订单ID')->setProp('id'),
            Column::txt()->setLabel('用户信息')->setProp('order_id')->setWidth(250),
            Column::txt()->setLabel('用户昵称')->setProp('user.nickname'),
            Column::txt()->setLabel('用户手机号码')->setProp('user.phone'),
            Column::txt()->setLabel('实际支付')->setProp('pay_price'),
            Column::txt()->setLabel('状态')->setProp('status'),
        ]);
        return $colum->toArray();
    }

    protected function getRoute($types = null)
    {
        if (is_null($types)) {
            return $this->routes;
        }
        return $this->routes[$types];
    }

    /**
     * @PostApi(path="config",description="配置")
     */
    public function config()
    {
        $routes = $this->getRoute();
        $column = $this->getColumn();
        _SUCCESS(compact('routes', 'column'));
    }

    /**
     * @PostApi(path="update",description="添加")
     */
    public function update()
    {
        $form = Elm::createForm($this->getRoute('add'));
        $form->setRule([
            Elm::input('title', '名称')->required(),

        ]);
        $lists = $form->setTitle('添加题库')->formData([]);
        _SUCCESS(formToData($lists));
    }
}